package com.lv.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lv.mapper.ClazzMapper;
import com.lv.pojo.Clazz;
import com.lv.pojo.Grade;
import com.lv.service.ClazzService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @Author:晓风残月Lx
 * @Date: 2022/4/28 18:54
 */
@Service("clazzSerivceImpl")
@Transactional
public class ClazzSerivceImpl extends ServiceImpl<ClazzMapper, Clazz> implements ClazzService {
    /**
     * 分页查询所有班级信息【带条件】
     * @param page
     * @param clazz
     * @return
     */
    @Override
    public IPage<Clazz> getClazzByOpr(Page<Clazz> page, Clazz clazz) {
        QueryWrapper<Clazz> queryWrapper=new QueryWrapper<>();
        String gradeName=clazz.getGradeName();
        String name=clazz.getName();
        // 年级名称条件
        if(!StringUtils.isEmpty(gradeName)){
            queryWrapper.like("grade_name",gradeName);
        }
        // 班级名称条件
        if(!StringUtils.isEmpty(name)){
            queryWrapper.like("name",name);
        }

        queryWrapper.orderByAsc("id");
        queryWrapper.orderByDesc("name");

        Page<Clazz> clazzPage = baseMapper.selectPage(page, queryWrapper);

        return clazzPage;
    }

    @Override
    public List<Clazz> getClazzs() {
        List<Clazz> clazzes = baseMapper.selectList(null);
        return clazzes ;
    }
}
